package com.leicx.guli.product.web;

import com.leicx.guli.product.entity.CategoryEntity;
import com.leicx.guli.product.service.CategoryService;
import com.leicx.guli.product.vo.catalog.Catalog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author daxiong
 * @date 2021/10/28 下午10:15
 */
@Controller
public class IndexController {

    @Resource
    CategoryService categoryService;

    @GetMapping(value = {"/", "/index.html"})
    public String index(Model model) {
        List<CategoryEntity> list = categoryService.listRootLevel();
        model.addAttribute("categories", list);
        return "index";
    }

    @GetMapping(value = "index/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJson();
    }

    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello";
    }

}
